package com.tmindtech.api.enterprise.db

import com.tmindtech.api.enterprise.model.EnterpriseCheckRecord
import org.apache.ibatis.annotations.Param
import org.apache.ibatis.annotations.Select
import tk.mybatis.mapper.common.Mapper
import java.util.*

/**
 * Created by RexQian on 2017/11/22.
 */
interface EnterpriseCheckRecordMapper : Mapper<EnterpriseCheckRecord> {
    @Select("SELECT * FROM t_enterprise_check_record WHERE enterprise_id = \${enterprise_id} AND result_type = 1 AND result_date >= #{start_time} AND result_date < #{end_time}")
    fun selectByCondition(@Param("enterprise_id") enterpriseId: Long,
                          @Param("start_time") startTime: Date,
                          @Param("end_time") endTime: Date): List<EnterpriseCheckRecord>

    @Select("SELECT COUNT(t_enterprise_check_record.id) FROM t_enterprise_check_record JOIN t_enterprise ON t_enterprise_check_record.enterprise_id = t_enterprise.id WHERE t_enterprise.manage_gov_id = \${gov_id} AND t_enterprise_check_record.result_date >= #{start_time} AND t_enterprise_check_record.result_date < #{end_time}")
    fun getCheckTimes(@Param("gov_id") govId: Long,
                      @Param("start_time") startTime: Date,
                      @Param("end_time") endTime: Date): Int
}
